#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdlib.h>

using namespace std;
typedef function<void()> func;
vector<func> callbacks;
int cnt = 0;

//功能
void showCount()
{
    cout << " final count: " << cnt << endl;
}

void showLog()
{
    cout<< "日志功能"<<endl;
}




// 定时器功能
void catchSig(int signum)
{
    //调用callbacks里面的函数
    for (auto &f : callbacks)
    {
        f();
    }
    alarm(1);
}

int main()
{
    signal(SIGALRM,catchSig);
    alarm(1);//设定了一个闹钟,其一旦触发,就自动销毁了

    callbacks.push_back(showCount);
    callbacks.push_back(showLog);

    
    while(1) cnt++;
    return 0;
}




